﻿using Myotragus.Data.Util;
using NUnit.Framework;

namespace Myotragus.Data.Tests.Tests.Utils
{
	[TestFixture]
	public class ReflectionHelperFixtures
	{
		public class TestComponent
		{
			public string StringProperty { get; set; }

			public int IntProperty { get; set; }

			public object ObjectProperty { get; set; }
		}

		public interface ITestCase
		{
			string P { get; set; }
		}

		public interface IA
		{
		}

		public interface IB
		{
		}

		public class ImplementationTestCase : ITestCase, IA, IB
		{
			public string P { get; set; }
		}

		[Test]
		public void DefaultInterface()
		{
			var def = ReflectionHelper.GetDefaultInterface(typeof (ImplementationTestCase));
			Assert.AreEqual(typeof (ITestCase), def);
		}

		[Test]
		public void InitializeObject()
		{
			var obj = new object();
			var result = new TestComponent
				{
					StringProperty = "string",
					IntProperty = 1,
					ObjectProperty = obj
				};

			ReflectionHelper.InitializeObject(result,
				new
				{
					StringProperty = "string2",
					StringProperty2 = "2"
				});

			Assert.AreEqual("string2", result.StringProperty);

			ReflectionHelper.InitializeObject(result,
				new
				{
					StringProperty = "string3",
					IntProperty = 2,
					ObjectProperty = (object)null
				});

			Assert.AreEqual("string3", result.StringProperty);
			Assert.AreEqual(2, result.IntProperty);
			Assert.AreEqual(null, result.ObjectProperty);
		}
	}
}